<template>
	<view class="container">
		<uni-forms ref="baseForm" labelPosition="left" border labelWidth="100px">
		<uni-forms-item label="手机号码">
			<uni-easyinput type="text"  v-model="phone" />
		</uni-forms-item>
		<uni-forms-item label="电子邮箱">
			<uni-easyinput type="text"  v-model="email" />
		</uni-forms-item>
		</uni-forms>
		
		<view style="padding:10px"></view>
		<button type="primary" @click="clickModify">修改</button>
	</view>
</template>

<script>
	import { websock } from '../../net/websock'
	import store from '../../store'

	export default {
		data() {
			return {
				phone: '',
				email: ''
			}
		},
		onLoad(params) {
			this.phone = params.phone || ''
			this.email = params.email || ''
		},
		methods: {
			async clickModify() {
				try {
					await websock.modifyName({phone: this.phone, email: this.email})
					store.userInfo = null
					uni.$emit('userInfoChange')
					uni.navigateBack()
				} catch (err) {
					console.error(err)
					uni.showToast({title: err.message || 'error'})
				}
			}
		}
	}
</script>

<style>
@import url("../common/common.css");
</style>
